package com.xm.servlet.reception_desk.error;

import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用于跳转报错页面
 * @author 康文程
 * @date 2023-12-5 下午 2:47
 */
@WebServlet("/error")
public class Error extends HttpServlet {

    /**
     * 跳转错误页面
     * @param req   an {@link HttpServletRequest} object that
     *                  contains the request the client has made
     *                  of the servlet
     *
     * @param resp  an {@link HttpServletResponse} object that
     *                  contains the response the servlet sends
     *                  to the client
     *
     */
    @SneakyThrows(Exception.class)
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
        //如果是找不到页面则用404 并且提示:哎呀! 页面找不到了。请稍后再试。 通常不需要传参
        String state = req.getParameter("state");
        String information = req.getParameter("information");

        req.setAttribute("state",state == null ? 500 : state);
        req.setAttribute("information",information==null ? "哎呀! 服务器错误。请稍后再试。" : information);

        req.getRequestDispatcher("/WEB-INF/page/exception.jsp").forward(req,resp);
    }

}
